package cn.gson.springmvc.model.pojos;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Objects;

@Entity
public class Purchase {
    private int purchaseId;
    private String purchasePeople;
    private Timestamp purchaseTime;
    private Long purchaseAllquantity;
    private Long purchaseAllm;
    private Collection<IndentDetailsOutbound> indentDetailsOutboundsByPurchaseId;
    private Supplier supplierBySupplierId;

    @Id
    @Column(name = "purchase_id", nullable = false)
    public int getPurchaseId() {
        return purchaseId;
    }

    public void setPurchaseId(int purchaseId) {
        this.purchaseId = purchaseId;
    }

    @Basic
    @Column(name = "purchase_people", nullable = true, length = 20)
    public String getPurchasePeople() {
        return purchasePeople;
    }

    public void setPurchasePeople(String purchasePeople) {
        this.purchasePeople = purchasePeople;
    }

    @Basic
    @Column(name = "purchase_time", nullable = true)
    public Timestamp getPurchaseTime() {
        return purchaseTime;
    }

    public void setPurchaseTime(Timestamp purchaseTime) {
        this.purchaseTime = purchaseTime;
    }

    @Basic
    @Column(name = "purchase_allquantity", nullable = true, precision = 0)
    public Long getPurchaseAllquantity() {
        return purchaseAllquantity;
    }

    public void setPurchaseAllquantity(Long purchaseAllquantity) {
        this.purchaseAllquantity = purchaseAllquantity;
    }

    @Basic
    @Column(name = "purchase_allm", nullable = true, precision = 0)
    public Long getPurchaseAllm() {
        return purchaseAllm;
    }

    public void setPurchaseAllm(Long purchaseAllm) {
        this.purchaseAllm = purchaseAllm;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Purchase purchase = (Purchase) o;
        return purchaseId == purchase.purchaseId &&
                Objects.equals(purchasePeople, purchase.purchasePeople) &&
                Objects.equals(purchaseTime, purchase.purchaseTime) &&
                Objects.equals(purchaseAllquantity, purchase.purchaseAllquantity) &&
                Objects.equals(purchaseAllm, purchase.purchaseAllm);
    }

    @Override
    public int hashCode() {
        return Objects.hash(purchaseId, purchasePeople, purchaseTime, purchaseAllquantity, purchaseAllm);
    }

    @OneToMany(mappedBy = "purchaseByPurchaseId")
    public Collection<IndentDetailsOutbound> getIndentDetailsOutboundsByPurchaseId() {
        return indentDetailsOutboundsByPurchaseId;
    }

    public void setIndentDetailsOutboundsByPurchaseId(Collection<IndentDetailsOutbound> indentDetailsOutboundsByPurchaseId) {
        this.indentDetailsOutboundsByPurchaseId = indentDetailsOutboundsByPurchaseId;
    }

    @ManyToOne
    @JoinColumn(name = "supplier_id", referencedColumnName = "supplier_id")
    public Supplier getSupplierBySupplierId() {
        return supplierBySupplierId;
    }

    public void setSupplierBySupplierId(Supplier supplierBySupplierId) {
        this.supplierBySupplierId = supplierBySupplierId;
    }
}
